<?php
include_once '../AtacCommunicator/ACBusWaitingTimes.php';
include_once '../Model/BusSocialFeatures.php';
include_once '../Utility/RMobUtils.php';
include_once '../Model/PersistentBus.php';
include_once '../Model/BusAtStop.php';
include_once '../Model/BusLine.php';
include_once '../Model/BusStop.php';

if(isset($_GET['vehicleID']) && isset($_GET['opCode']) && isset($_GET['fbID'])){
	switch($_GET['opCode']){
		case 1: //sali su un autobus
			if(isset($_GET['stopID']))
				catchABus();
			break;
		case 2: //scendi da un autobus
			dropFromBus();
			break;
	}
}

function catchABus(){
	$ac = new ACBusWaitingTimes();
	$stop = new BusStop(null,RMobUtils::escape_var($_GET['stopID']));
	$buses = $ac->getIncomingBusesAtStop($stop);
	foreach($buses as $bus){
		echo $bus->getLineID()."\n";
		if($bus->getLineID() == RMobUtils::escape_var($_GET['vehicleID'])){
			$busAtStop = $bus;
			break;
		}
	}
	if(!isset($busAtStop)){
		return;
	}

	$socialHandler = new BusSocialFeatures($busAtStop->getLineID());
	$ret = $socialHandler->catchBus(RMobUtils::escape_var($_GET['fbID']));
	echo $ret;
}

function dropFromBus(){
	$socialHandler = new BusSocialFeatures(RMobUtils::escape_var($_GET['vehicleID']));
	$socialHandler->dropSpecificPerson(RMobUtils::escape_var($_GET['fbID']));
}
?>
